﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataBase
/// </summary>

public static class DataBase
{
    public static string MyConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True";
    public static SqlConnection MyConnection = new SqlConnection(MyConnectionString);

    public static SqlDataReader SelectData(string selectQuery)
    {
        SqlCommand myCommand = new SqlCommand(selectQuery);
        myCommand.Connection = MyConnection;
        myCommand.Cancel();
        SqlDataReader reader = myCommand.ExecuteReader();

        return reader;
    }

    public static void OpenConnection()
    {
        if(MyConnection.State != System.Data.ConnectionState.Open)
            MyConnection.Open();
    }

    public static void CloseConnection()
    {
        if (MyConnection.State != System.Data.ConnectionState.Closed)
            MyConnection.Close();
    }
}